package cn.wd.web.controller;

import cn.wd.domain.ReportTable;
import cn.wd.page.PageResult;
import cn.wd.qo.QueryObject;
import cn.wd.qo.ReportTableQueryObject;
import cn.wd.service.IReportTableService;
import cn.wd.vo.JsonResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/report")
public class ReportTableController {

    private final IReportTableService reportTableService;

    public ReportTableController(IReportTableService reportTableService) {
        this.reportTableService = reportTableService;
    }

    @RequestMapping("/list")
    public JsonResult<PageResult<ReportTable>> list(ReportTableQueryObject qo) {
        return JsonResult.success(reportTableService.query(qo));
    }

    @RequestMapping("/saveOrUpdate")
    public JsonResult<?> saveOrUpdate(@RequestBody ReportTable reportTable) {
        if (reportTable.getId() != null){
            reportTableService.updateById(reportTable);
        }else {
            reportTableService.save(reportTable);
        }
        return JsonResult.success();
    }

    @RequestMapping("/delete")
    public JsonResult<?> delete(Long id) {
        if (id == null) {
            JsonResult.failed(401,"id 不能为空!");
        }
        reportTableService.deleteById(id);
        return JsonResult.success();
    }
}
